home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ScrollingPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  7.4 KB  |  459 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.awt.LayoutManager;
  9. import java.awt.Rectangle;
  10. import java.awt.Scrollbar;
  11. import symantec.itools.awt.shape.Rect;
  12.  
  13. public class ScrollingPanel extends KeyPressManagerPanel {
  14.    private Component spComponent;
  15.    private int width;
  16.    private int height;
  17.    private int xCoord;
  18.    private int yCoord;
  19.    private Scrollbar VBar;
  20.    private Scrollbar HBar;
  21.    private boolean bVBarVisible;
  22.    private boolean bHBarVisible;
  23.    private boolean bCornerRectVisible;
  24.    private boolean bOsFlag;
  25.    private int vPageSize;
  26.    private int hPageSize;
  27.    private Dimension dimComponent;
  28.    private int vGapWid;
  29.    private int hGapHt;
  30.    private boolean bAllowShowVBar;
  31.    private boolean bAllowShowHBar;
  32.    private int scrollLineIncrement;
  33.    private Rect cornerRect;
  34.  
  35.    public ScrollingPanel() {
  36.       this((Component)null, 0, 0);
  37.    }
  38.  
  39.    public ScrollingPanel(Component var1, int var2, int var3) {
  40.       this.bAllowShowVBar = true;
  41.       this.bAllowShowHBar = true;
  42.       this.scrollLineIncrement = 1;
  43.       this.bOsFlag = System.getProperty("os.name").startsWith("S");
  44.       this.spComponent = var1;
  45.       this.width = var2;
  46.       this.height = var3;
  47.       this.xCoord = 0;
  48.       this.yCoord = 0;
  49.       this.bVBarVisible = false;
  50.       this.bHBarVisible = false;
  51.       this.bCornerRectVisible = false;
  52.       this.vPageSize = 0;
  53.       this.hPageSize = 0;
  54.       this.vGapWid = 6;
  55.       this.hGapHt = 6;
  56.       this.dimComponent = new Dimension(0, 0);
  57.       this.VBar = new Scrollbar();
  58.       this.VBar.setBackground(Color.lightGray);
  59.       this.HBar = new Scrollbar(0);
  60.       this.HBar.setBackground(Color.lightGray);
  61.       this.cornerRect = new Rect();
  62.       this.cornerRect.setForeground(Color.lightGray);
  63.       this.cornerRect.setFillColor(Color.lightGray);
  64.       this.cornerRect.setFillMode(true);
  65.       this.setLayout((LayoutManager)null);
  66.       super.add(this.VBar, -1);
  67.       super.add(this.HBar, -1);
  68.       super.add(this.cornerRect, -1);
  69.       this.VBar.hide();
  70.       this.HBar.hide();
  71.       this.cornerRect.hide();
  72.       if (this.spComponent != null) {
  73.          super.add(this.spComponent, -1);
  74.          this.placeComponents();
  75.       }
  76.  
  77.    }
  78.  
  79.    public void setMinimumWidth(int var1) {
  80.       this.width = var1;
  81.    }
  82.  
  83.    public int getMinimumWidth() {
  84.       return this.width;
  85.    }
  86.  
  87.    public void setMinimumHeight(int var1) {
  88.       this.height = var1;
  89.    }
  90.  
  91.    public int getMinimumHeight() {
  92.       return this.height;
  93.    }
  94.  
  95.    public void setVerticalGap(int var1) {
  96.       this.vGapWid = var1;
  97.       ((Component)this).invalidate();
  98.    }
  99.  
  100.    public int getVerticalGap() {
  101.       return this.vGapWid;
  102.    }
  103.  
  104.    public void setHorizontalGap(int var1) {
  105.       this.hGapHt = var1;
  106.       ((Component)this).invalidate();
  107.    }
  108.  
  109.    public int getHorizontalGap() {
  110.       return this.hGapHt;
  111.    }
  112.  
  113.    public void setShowVerticalScroll(boolean var1) {
  114.       if (this.bAllowShowVBar != var1) {
  115.          this.bAllowShowVBar = var1;
  116.          ((Component)this).invalidate();
  117.       }
  118.  
  119.    }
  120.  
  121.    public boolean getShowVerticalScroll() {
  122.       return this.bAllowShowVBar;
  123.    }
  124.  
  125.    public void setShowHorizontalScroll(boolean var1) {
  126.       if (this.bAllowShowHBar != var1) {
  127.          this.bAllowShowHBar = var1;
  128.          ((Component)this).invalidate();
  129.       }
  130.  
  131.    }
  132.  
  133.    public boolean getShowHorizontalScroll() {
  134.       return this.bAllowShowHBar;
  135.    }
  136.  
  137.    public void setScrollLineIncrement(int var1) {
  138.       this.scrollLineIncrement = var1;
  139.    }
  140.  
  141.    public int getScrollLineIncrement() {
  142.       return this.scrollLineIncrement;
  143.    }
  144.  
  145.    public void setComponent(Component var1) {
  146.       if (this.spComponent != null) {
  147.          super.remove(this.spComponent);
  148.       }
  149.  
  150.       this.spComponent = var1;
  151.       super.add(this.spComponent, -1);
  152.       ((Component)this).invalidate();
  153.    }
  154.  
  155.    public Component getComponent() {
  156.       return this.spComponent;
  157.    }
  158.  
  159.    public boolean handleEvent(Event var1) {
  160.       switch (var1.id) {
  161.          case 601:
  162.             if (var1.target == this.HBar) {
  163.                this.scrollLeft();
  164.             } else {
  165.                this.scrollUp();
  166.             }
  167.  
  168.             return true;
  169.          case 602:
  170.             if (var1.target == this.HBar) {
  171.                this.scrollRight();
  172.             } else {
  173.                this.scrollDown();
  174.             }
  175.  
  176.             return true;
  177.          case 603:
  178.             if (var1.target == this.HBar) {
  179.                this.scrollPageLeft();
  180.             } else {
  181.                this.scrollPageUp();
  182.             }
  183.  
  184.             return true;
  185.          case 604:
  186.             if (var1.target == this.HBar) {
  187.                this.scrollPageRight();
  188.             } else {
  189.                this.scrollPageDown();
  190.             }
  191.  
  192.             return true;
  193.          case 605:
  194.             if (var1.target == this.HBar) {
  195.                this.scrollHorizontalAbsolute((Integer)var1.arg);
  196.             } else {
  197.                this.scrollVerticalAbsolute((Integer)var1.arg);
  198.             }
  199.  
  200.             return true;
  201.          default:
  202.             return super.handleEvent(var1);
  203.       }
  204.    }
  205.  
  206.    public void update(Graphics var1) {
  207.       this.paint(var1);
  208.    }
  209.  
  210.    public void paint(Graphics var1) {
  211.       if (this.spComponent != null) {
  212.          this.placeComponents();
  213.       }
  214.    }
  215.  
  216.    public void scrollUp() {
  217.       this.yCoord += this.scrollLineIncrement;
  218.       if (this.yCoord > 0) {
  219.          this.yCoord = 0;
  220.       }
  221.  
  222.       this.VBar.setValue(-this.yCoord);
  223.       ((Component)this).repaint();
  224.    }
  225.  
  226.    public void scrollLeft() {
  227.       this.xCoord += this.scrollLineIncrement;
  228.       if (this.xCoord > 0) {
  229.          this.xCoord = 0;
  230.       }
  231.  
  232.       this.HBar.setValue(-this.xCoord);
  233.       ((Component)this).repaint();
  234.    }
  235.  
  236.    public void scrollDown() {
  237.       this.yCoord -= this.scrollLineIncrement;
  238.       if (-this.yCoord > this.VBar.getMaximum()) {
  239.          this.yCoord = -this.VBar.getMaximum();
  240.       }
  241.  
  242.       this.VBar.setValue(-this.yCoord);
  243.       ((Component)this).repaint();
  244.    }
  245.  
  246.    public void scrollRight() {
  247.       this.xCoord -= this.scrollLineIncrement;
  248.       if (-this.xCoord > this.HBar.getMaximum()) {
  249.          this.xCoord = -this.HBar.getMaximum();
  250.       }
  251.  
  252.       this.HBar.setValue(-this.xCoord);
  253.       ((Component)this).repaint();
  254.    }
  255.  
  256.    public void scrollPageUp() {
  257.       this.yCoord += this.vPageSize;
  258.       if (this.yCoord > 0) {
  259.          this.yCoord = 0;
  260.       }
  261.  
  262.       this.VBar.setValue(-this.yCoord);
  263.       ((Component)this).repaint();
  264.    }
  265.  
  266.    public void scrollPageLeft() {
  267.       this.xCoord += this.hPageSize;
  268.       if (this.xCoord > 0) {
  269.          this.xCoord = 0;
  270.       }
  271.  
  272.       this.HBar.setValue(-this.xCoord);
  273.       ((Component)this).repaint();
  274.    }
  275.  
  276.    public void scrollPageDown() {
  277.       this.yCoord -= this.vPageSize;
  278.       if (-this.yCoord > this.VBar.getMaximum()) {
  279.          this.yCoord = -this.VBar.getMaximum();
  280.       }
  281.  
  282.       this.VBar.setValue(-this.yCoord);
  283.       ((Component)this).repaint();
  284.    }
  285.  
  286.    public void scrollPageRight() {
  287.       this.xCoord -= this.hPageSize;
  288.       if (-this.xCoord > this.HBar.getMaximum()) {
  289.          this.xCoord = -this.HBar.getMaximum();
  290.       }
  291.  
  292.       this.HBar.setValue(-this.xCoord);
  293.       ((Component)this).repaint();
  294.    }
  295.  
  296.    public void scrollVerticalAbsolute(int var1) {
  297.       this.yCoord = -var1;
  298.       if (this.yCoord > 0) {
  299.          this.yCoord = 0;
  300.       } else if (-this.yCoord > this.VBar.getMaximum()) {
  301.          this.yCoord = -this.VBar.getMaximum();
  302.       }
  303.  
  304.       this.VBar.setValue(-this.yCoord);
  305.       ((Component)this).repaint();
  306.    }
  307.  
  308.    public void scrollHorizontalAbsolute(int var1) {
  309.       this.xCoord = -var1;
  310.       if (this.xCoord > 0) {
  311.          this.xCoord = 0;
  312.       } else if (-this.xCoord > this.HBar.getMaximum()) {
  313.          this.xCoord = -this.HBar.getMaximum();
  314.       }
  315.  
  316.       this.HBar.setValue(-this.xCoord);
  317.       ((Component)this).repaint();
  318.    }
  319.  
  320.    public Dimension preferredSize() {
  321.       Dimension var1 = ((Component)this).size();
  322.       Dimension var2 = this.minimumSize();
  323.       return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
  324.    }
  325.  
  326.    public Dimension minimumSize() {
  327.       return new Dimension(this.width, this.height);
  328.    }
  329.  
  330.    public Component add(Component var1) {
  331.       if (this.spComponent != null) {
  332.          super.remove(this.spComponent);
  333.       }
  334.  
  335.       this.spComponent = var1;
  336.       super.add(this.spComponent, -1);
  337.       ((Component)this).repaint();
  338.       return var1;
  339.    }
  340.  
  341.    public synchronized Component add(Component var1, int var2) {
  342.       return this.add(var1);
  343.    }
  344.  
  345.    public synchronized Component add(String var1, Component var2) {
  346.       return this.add(var2);
  347.    }
  348.  
  349.    public synchronized void remove(Component var1) {
  350.       if (var1 != this.VBar && var1 != this.HBar) {
  351.          super.remove(var1);
  352.          if (var1 == this.spComponent) {
  353.             this.spComponent = null;
  354.          }
  355.  
  356.       }
  357.    }
  358.  
  359.    public synchronized void removeAll() {
  360.       super.removeAll();
  361.       super.add(this.VBar, -1);
  362.       super.add(this.HBar, -1);
  363.       super.add(this.cornerRect, -1);
  364.       this.spComponent = null;
  365.    }
  366.  
  367.    public void setLayout(LayoutManager var1) {
  368.    }
  369.  
  370.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  371.       ((Component)this).repaint();
  372.       super.reshape(var1, var2, var3, var4);
  373.    }
  374.  
  375.    void placeComponents() {
  376.       int var3 = 0;
  377.       int var4 = 0;
  378.       int var5 = 0;
  379.       this.dimComponent = this.spComponent.size();
  380.       Rectangle var6 = ((Component)this).bounds();
  381.       var3 = this.bOsFlag ? 17 : 15;
  382.       boolean var2;
  383.       if (this.bAllowShowHBar && this.dimComponent.width > var6.width) {
  384.          var2 = true;
  385.          var5 = var3;
  386.       } else {
  387.          var2 = false;
  388.          var5 = 0;
  389.       }
  390.  
  391.       boolean var1;
  392.       if (this.bAllowShowVBar && this.dimComponent.height > var6.height - var5) {
  393.          var1 = true;
  394.          var4 = var3;
  395.          if (!var2 && this.dimComponent.width > var6.width - var3) {
  396.             var2 = true;
  397.             var5 = var3;
  398.          }
  399.       } else {
  400.          var1 = false;
  401.          var4 = 0;
  402.       }
  403.  
  404.       this.hPageSize = var6.width - var4 - this.vGapWid;
  405.       this.vPageSize = var6.height - var5 - this.hGapHt;
  406.       if (var1) {
  407.          this.VBar.reshape(var6.width - var3, 0, var3, var6.height - var5);
  408.          this.VBar.setValues(-this.yCoord, this.vPageSize, 0, this.dimComponent.height - this.vPageSize);
  409.          this.VBar.setPageIncrement(this.vPageSize);
  410.          if (!this.bVBarVisible) {
  411.             this.bVBarVisible = true;
  412.             this.VBar.show();
  413.          }
  414.       } else {
  415.          if (this.bVBarVisible) {
  416.             this.bVBarVisible = false;
  417.             this.VBar.hide();
  418.          }
  419.  
  420.          this.yCoord = 0;
  421.       }
  422.  
  423.       if (var2) {
  424.          this.HBar.reshape(0, var6.height - var3, var6.width - var4, var3);
  425.          this.HBar.setValues(-this.xCoord, this.hPageSize, 0, this.dimComponent.width - this.hPageSize);
  426.          this.HBar.setPageIncrement(this.hPageSize);
  427.          if (!this.bHBarVisible) {
  428.             this.bHBarVisible = true;
  429.             this.HBar.show();
  430.          }
  431.       } else {
  432.          if (this.bHBarVisible) {
  433.             this.bHBarVisible = false;
  434.             this.HBar.hide();
  435.          }
  436.  
  437.          this.xCoord = 0;
  438.       }
  439.  
  440.       if (this.bHBarVisible && this.bVBarVisible) {
  441.          int var7 = var6.width - var4;
  442.          int var8 = var6.height - var5;
  443.          int var9 = var6.width - var7 + 1;
  444.          int var10 = var6.height - var8 + 1;
  445.          this.cornerRect.reshape(var7, var8, var9, var10);
  446.          if (!this.bCornerRectVisible) {
  447.             this.bCornerRectVisible = true;
  448.             this.cornerRect.show();
  449.          }
  450.       } else if (this.bCornerRectVisible) {
  451.          this.bCornerRectVisible = false;
  452.          this.cornerRect.hide();
  453.       }
  454.  
  455.       this.spComponent.move(this.xCoord, this.yCoord);
  456.       this.spComponent.validate();
  457.    }
  458. }
  459.